import { defineStore } from 'pinia'
import { ref } from 'vue'
import { realnameAPI } from '@/api/realname/index.js'

export const useRealnameStore = defineStore('realname', () => {
    const authList = ref([])
    const pageInfo = ref({
        total: 0,
        pageNumber: 1,
        pageSize: 10
    })

    // 获取待审核实名认证列表
    const getPendingAuthList = async (params) => {
        try {
            const res = await realnameAPI.getPendingAuthList(params)
            authList.value = res.data.list || []
            pageInfo.value = {
                total: res.data.total || 0,
                pageNumber: params.pageNumber || 1,
                pageSize: params.pageSize || 10
            }
            return res
        } catch (error) {
            throw error
        }
    }

    // 审核实名认证
    const verifyAuth = async (data) => {
        try {
            const res = await realnameAPI.verifyAuth(data)
            return res
        } catch (error) {
            throw error
        }
    }

    return {
        authList,
        pageInfo,
        getPendingAuthList,
        verifyAuth
    }
})